package com.pattern.bridge;

/**
 * @author Mr.yuan
 * @version v1.0
 * @date 2019/7/31 17:50
 * 桥接模式
 **/
public class BridgePattern {
    public static void main(String[] args) {
        Circle redCircle = new Circle(100,10,19,new RedCircle());
        Circle greenCircle = new Circle(200,29,33,new GreenCircle());
        redCircle.draw();
        greenCircle.draw();
    }

    private interface DrawAPI{
        void draw(int x,int y,int radius);
    }
    private static class RedCircle implements DrawAPI{

        @Override
        public void draw(int x,int y,int radius) {
            System.out.println("this is redCircle,shape:{x-"+x+",y-"+y+",radius-"+radius+"}");
        }
    }
    private static class GreenCircle implements DrawAPI{
        @Override
        public void draw(int x, int y, int radius) {
            System.out.println("this is greenCircle,shape:{x-"+x+",y-"+y+",radius-"+radius+"} ");
        }
    }
    private static abstract class Shape {
        protected DrawAPI drawAPI;

        private Shape(DrawAPI drawAPI) {
            this.drawAPI = drawAPI;
        }

        abstract void draw();
    }
    private static class Circle extends Shape{
        private int x,y,radius;

        public Circle(int x, int y, int radius,DrawAPI drawAPI) {
            super(drawAPI);
            this.x = x;
            this.y = y;
            this.radius = radius;
        }

        @Override
        void draw() {
            drawAPI.draw(x,y,radius);
        }
    }
}
